package com.futures.questionbank.ui.home;

import android.content.Intent;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.futures.questionbank.R;
import com.futures.questionbank.Utils.UItils;
import com.futures.questionbank.adapter.BaseViewHolder;
import com.futures.questionbank.adapter.ChapterAdpter;
import com.futures.questionbank.base.BaseActivity;
import com.futures.questionbank.db.table.chapter;
import com.futures.questionbank.main.SectionActivity;
import com.raizlabs.android.dbflow.sql.language.SQLite;

import java.util.List;

import butterknife.BindView;

/**
 * author : huang
 * date   : 2020/6/16 0016 14:39
 * version: 1.0
 */
public class ZhangJiActivity extends BaseActivity {

    @BindView(R.id.rv)
    RecyclerView rv;
    private List<chapter> users;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.zhangji_activity);
        setTitle("章节测试卷");
    }

    @Override
    protected void loadData() {
        UItils.showDialog(this);
        users = SQLite.select().
                from(chapter.class).
                queryList();
        rv.setLayoutManager(new LinearLayoutManager(this));
        //设置Item增加、移除动画
        rv.setItemAnimator(new DefaultItemAnimator());
        ChapterAdpter chapterAdpter = new ChapterAdpter(this, users, new TypeItemListener());
        rv.setAdapter(chapterAdpter);


    }

    class TypeItemListener implements BaseViewHolder.onItemCommonClickListener {
        @Override
        public void onItemClickListener(int position) {
            Intent intent = new Intent();
            intent.putExtra("index", users.get(position).getIndex());
            intent.setClass(ZhangJiActivity.this, SectionActivity.class);
            startActivity(intent);
        }

        @Override
        public void onItemLongClickListener(int position) {

        }
    }
}
